home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / PictureFrame.java < prev    next >
Text File  |  1998-09-15  |  2KB  |  62 lines

  1. package alternative;
  2.  
  3. import java.awt.*;
  4.  
  5. public class PictureFrame extends Frame {
  6.     boolean inAnApplet = true;
  7.     Image image;
  8.  
  9.     PictureFrame(Image image, int width, int height) {
  10.     super("PictureFrame");
  11.  
  12.     GridBagLayout gridbag = new GridBagLayout();
  13.     GridBagConstraints c = new GridBagConstraints();
  14.     setLayout(gridbag);
  15.  
  16.     //Create the image and start downloading it.
  17.     MediaTracker tracker = new MediaTracker(this);
  18.     this.image = image;
  19.     tracker.addImage(image, 0);
  20.     tracker.checkAll(true);
  21.  
  22.     c.gridwidth = GridBagConstraints.REMAINDER;
  23.     c.weightx = 1.0;
  24.     Label label1 = new Label("Here's what you'd see if you were using "
  25.                          + "a 1.1-compatible browser:");
  26.     gridbag.setConstraints(label1, c);
  27.     add(label1);
  28.  
  29.     c.weighty = 1.0;
  30.     ImageDisplayer imageDisplayer = new ImageDisplayer(image,
  31.                                width,
  32.                                height);
  33.     gridbag.setConstraints(imageDisplayer, c);
  34.     add(imageDisplayer);
  35.  
  36.     c.weighty = 0.0;
  37.     Label label2 = new Label("Remember, this is just a picture!");
  38.     label2.setForeground(Color.red);
  39.     gridbag.setConstraints(label2, c);
  40.     add(label2);
  41.     }
  42.  
  43.     public boolean handleEvent(Event e) {
  44.     if (e.id == Event.WINDOW_DESTROY) {
  45.         if (inAnApplet) {
  46.         dispose();
  47.         } else {
  48.         System.exit(0);
  49.         }
  50.     }
  51.     return super.handleEvent(e);
  52.     }
  53.  
  54.     public static void main(String[] args) {
  55.     PictureFrame frame = 
  56.         new PictureFrame(Toolkit.getDefaultToolkit().getImage("Beeper.gif"), 200, 200);
  57.     frame.inAnApplet = false;
  58.         frame.pack();
  59.         frame.show();
  60.     }
  61. }
  62.